<html>
<head>
<link rel="stylesheet" href="moneystyle.css">
</head>
<body>
	<div class=newpayment>
		<div class=newpaymentleft>
			<h2>New payment plan</h2>
			<form action="newpayment.php" method="post">
				<table>
					<tr>
						<td>Name</td>				
						<td><input type="text" name="name"></td>
					</tr>
					<tr>
						<td>Amount</td>				
						<td><input type="text" name="amount"></td>
					</tr>
					<tr>
						<td>Frequency</td>
						<td>	
						<select name="frequency">
							<option>Daily</option>
							<option>Weekly</option>
							<option>Monthly</option>
							<option>Annually</option>
							<option>Once only</option>
						</select>
						</td>
					</tr>
					<tr>
						<td>Due date</td>
						<td>
						<select name="duedate">
						<?php 
							for ($i = 1; $i < 32; $i++){
								echo "<option>".$i."</option>";
							}
						?>
						</select>
						</td>
					</tr>
					<tr>
						<td>Late fee</td>
						<td>		
						<select name="latefee">
							<option>Per day</option>
							<option>Per month</option>
							<option>Once only</option>
						</select>
						</td>
						<td>Late fee
						<input name="lateamount" type="text" size="5"></td>
					</tr>	
				</table>
				<input type="submit">
			</form>
			
			<?php 
				require '../dbconnect.php';
				
				$name = &$_POST['name'];
				$amount = &$_POST['amount'];
				$frequency = &$_POST['frequency'];
				$duedate = &$_POST['duedate'];
				$latefee = &$_POST['latefee'];
				$lateamount = &$_POST['lateamount'];
				
				if(isset($name)){
					$query = sprintf("INSERT INTO paymentplan (name, amount, frequency, duedate, latefee, lateamount) VALUES ('%s','%s','%s','%s','%s','%s')",
					mysql_real_escape_string($name),
					mysql_real_escape_string($amount),
					mysql_real_escape_string($frequency),
					mysql_real_escape_string($duedate),
					mysql_real_escape_string($latefee),
					mysql_real_escape_string($lateamount)
					);
					mysql_query($query);
				}	
			?>
		</div> <!-- left side -->
		
		<div class=newpaymentright>
			<h2>Latest payment plans</h2>
			<?php 
				$result = mysql_query("SELECT * FROM paymentplan");
				echo "<table border='1'>
		        <tr>
		            <th>Name</th>
		            <th>Amount</th>
		            <th>Frequency</th>
		            <th>Due date</th>
		            <th>Late fee</th>
		            <th>Late amoount</th>
		        </tr>";
		    	
		    	while($row = mysql_fetch_array($result)){
		    	    echo "<tr>";
		    	    echo "<td>". $row['name']. "</td>";
		    	    echo "<td>". $row['amount']. "</td>";
		    	    echo "<td>". $row['frequency']. "</td>";
		    	    echo "<td>". $row['duedate']. "</td>";
		    	    echo "<td>". $row['latefee']. "</td>";
		    	    echo "<td>". $row['lateamount']. "</td>";
		    	}
		    	
		    	echo "</table>";
			
			?>
		</div> <!-- right side -->
	<a href="Money.php">BACK</a>	
	</div> <!-- main div -->
</body>
</html>
